<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
	<%@ taglib prefix='sec' uri='http://www.springframework.org/security/tags'%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
	<script type="text/javascript" src="scripts/boot.js"></script>
</head>
<body>
	<div class="mini-toolbar" style="border-bottom:0;padding:0px;">
	  	<table style="width:100%;">
			<tr>
				<td>
					<sec:authorize url='/orders_add.do'>
				    <a class="mini-button" iconCls="icon-add" onclick="add()" id="btn_add_orders">下订单</a>
				    </sec:authorize>
				    <sec:authorize url='/orders_del.do'>
			        <a class="mini-button" iconCls="icon-remove" onclick="remove()">删除</a>
			        </sec:authorize>
				</td>
			</tr>
		</table>
	</div>
	<input id="customer_id" class="mini-hidden" />
	<div id="datagrid1" class="mini-datagrid" style="width:100%;height:auto;" allowCellWrap="true" url="orders_view.do" idField="id" showPager="false" >
		<div property="columns">
			<div type="indexcolumn" width="5px;"></div>
			<div field="serialNum" width="10px;" headerAlign="center" align="center">订单编号</div>
			<div field="payTypeVal" width="10px;" headerAlign="center" align="center">支付方式</div>
			<div header="各系统状态" headerAlign="center">
				<div property="columns">
					<div field="callStatus" width="10" headerAlign="center" align="center" >话务系统</div>
					<div field="ordersStatus" width="10" headerAlign="center" align="center" >订单系统</div>
					<div field="warehouseStatus" width="10" headerAlign="center" align="center" >仓储系统</div>
					<div field="financialStatus" width="10" headerAlign="center" align="center" >财务系统</div>
				</div>
			</div>
			<div field="totalPaid" width="10px;" headerAlign="center" align="center">总金额</div>
			<div field="ordersProduct" width="25px;" headerAlign="center" align="center">物品</div>
			<div field="createTime" width="25px;" headerAlign="center" dateFormat="yyyy-MM-dd HH:mm:ss" align="center">订单时间</div>
			<div field="address" width="25px;" headerAlign="center" align="center">详细地址</div>
			<sec:authorize url='/orders_edit_operate.do'>
			<div field="pocessingStatus" width="10" headerAlign="center" renderer="onActionRenderer" align="center">相关操作</div>
			</sec:authorize>
		</div>
	</div>
<script type="text/javascript">
mini.parse();
var grid = mini.get("datagrid1");

var cId = mini.get("customer_id");
function SetData(data) {
	data = mini.clone(data);
	if(data.openType == "play" && data.callStatus == "28") {	// 弹屏打开任务，任务在主管处不允许下单，在当前话务员处才可以下单
		var btnAddOrders = mini.get("btn_add_orders");
		btnAddOrders.hide();
	} 
	cId.setValue(data.customerId);
	grid.load({customerId: data.customerId});
}

// 下订单页面
function add() {
    mini.open({
        url: "orders_add.do",
        title: "下订单", width: 850, height: 700,
        onload: function () {
            var iframe = this.getIFrameEl();
            var data = { cId: cId.getValue() };
            iframe.contentWindow.SetData(data);
        },
        ondestroy: function (action) {
        	if(action == 'succ'){
        		mini.showMessageBox({
                    title: "提示",
                    showModal:false,
                    iconCls: "mini-messagebox-info",
                    message: "订单生效！",
                    timeout: 3000,
                    x: 'right',
                    y: 'bottom'
                });
        	}
            grid.reload();
        }
    });
}

//打开订单
function onActionRenderer(e) {
	return '<a href="javascript: openOrders();">打开订单</a>';
}

// 打开订单
function openOrders() {
    var row = grid.getSelected();
    if (row) {
    	mini.open({
            url: "orders_edit.do?id="+row.id,
            title: "修改订单信息", width: 850, height: 750,
            onload: function () {
                var iframe = this.getIFrameEl();
                var data = { row: row };
                iframe.contentWindow.SetData(data);
            },
            ondestroy: function (action) {
            	if(action == 'succ'){
            		mini.showMessageBox({
                        title: "提示",
                        showModal:false,
                        iconCls: "mini-messagebox-info",
                        message: "订单生效！",
                        timeout: 3000,
                        x: 'right',
                        y: 'bottom'
                    });
            	}
                grid.reload();
            }
        });
    } else {
        mini.alert("请选中一条记录");
    }
}

// 删除订单
function remove(){
    var row = grid.getSelected();
    if (row) {
    	if(row.callStatusVal == 38) {
    		mini.confirm("确定删除订单？", "删除订单",function (action) {
				if (action == "ok") {
					$.post("orders_del.do", {id: row.id}, function(data) {
						if(data.success) {
							grid.reload();
						}
					}, "json");
				}
			});
        }else {
    		mini.alert("订单已生效，无法删除！");
    	}
    } else {
        mini.alert("请选中一条记录");
    }
}

</script>
</body>
</html>